<?php
/**
 * 产品
 * @author Administrator
 *
 */
class Application_Model_DbTable_Product extends Application_Model_DbTable_Base
{
    protected $_name = 'product';

	/**
	 * 取得列表
	 */
	public function getUserListForFlex($pageM = NULL){
		$rows = $this->jqfetchAll($pageM);
		return $rows;
	}
	
	/**
	 * 统一的添加下拉列表项目
	 * @param Application_Form_Base $formM
	 */
	public function setMultiOptions(Application_Form_Base $formM){
		//添加分类
		$categoryE = $formM->getElement("category");
		if($categoryE){
			$categoryM = new Application_Model_DbTable_Productcategory();
			$categoryL = $categoryM->fetchAll();
			$categoryD = array();
			foreach ($categoryL as $category){
				$categoryD[$category["id"]] = $category["name"] ;
			}
			$categoryE->setMultiOptions($categoryD);
		}
		
		//添加供货商
		$factoryE = $formM->getElement("factory");
		if($factoryE){
			$factoryM = new Application_Model_DbTable_Customer();
			$factoryL = $factoryM->fetchAll(" `type` IN (1,2) ");
			$factoryD = array();
			foreach ($factoryL as $factory){
				$factoryD[$factory["id"]] = $factory["name"] ;
			}
			$factoryE->setMultiOptions($factoryD);
		}
		
		//添加货币
		$currencyE = $formM->getElement("currency");
		if($currencyE){
			$currencyM = new Application_Model_DbTable_Currency();
			$currencyL = $currencyM->fetchAll();
			$currencyD = array();
			foreach ($currencyL as $currency){
				$currencyD[$currency["id"]] = $currency["name"]."(".$currency["abbreviation"].")";
			}
			$currencyE->setMultiOptions($currencyD);
		}
		return $formM;
	}

}

